<template>
	<view class="container">
		<view class="content">
			<view class="list" v-for="(item,index) in couponList" :key="index">
				<view class="kuang">
					<view>
						<text>￥</text>
						<text class="big">{{item.coupon_price}}</text>
					</view>
				</view>
				<view class="text">
					<view class="big">满{{item.use_min_price}}元减{{item.coupon_price}}元</view>
					<view class="small">有效期：{{item.end_time}}</view>
				</view>
				<view class="btns gray" v-if="item.used !== null">已领取</view>
				<view class="btns" @click="selectClick(item)" v-else>立即领取</view>
			</view>
		</view>
		<u-loadmore :status="status" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				couponList: [],
				page: 1,
				pageSize: 10,
				total: 1,
				count: 1,
				status: 'loadmore'
			}
		},
		onLoad() {
			this.getData()
		},
		onReachBottom() {
			if (this.page >= this.count) return this.status = 'nomore';
			this.status = 'loading';
			this.page = ++this.page;
			this.getData()
		},
		methods: {
			selectClick(item) {
				this.$allApi.receiveCoupon({
					couponId: item.id
				}).then(res => {
					this.$u.toast('领取成功')
					this.page = 1
					this.couponList = []
					this.getData()
				})
			},
			getData() {
				this.$allApi.getCouponList({
					page: this.page,
					limit: this.pageSize
				}).then(res => {

					if (this.page == 1) {
						this.couponList = res.data
					} else {
						this.couponList = [...this.couponList, ...res.data.list.data]
					}
					if (res.data.length < 10) {
						this.status = 'nomore'
					} else {
						this.status = 'loadmore'
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.container {
		min-height: 100vh;
		padding-bottom: 120rpx;
		padding: 20rpx;
	}

	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #fff;
		width: 710rpx;
		height: 210rpx;
		box-shadow: 0rpx 4rpx 7rpx 1rpx rgba(100, 100, 100, 0.14);
		margin-bottom: 20rpx;
		border-radius: 20rpx;
		overflow: hidden;

		.text {
			flex: 1;
			padding-left: 20rpx;

			.big {
				font-size: 32rpx;
				font-weight: bold;
			}

			.small {
				font-size: 20rpx;
				margin-top: 12rpx;
			}
		}

		.btns {
			width: 160rpx;
			height: 62rpx;
			border-radius: 32rpx;
			background: #FFFFFF;
			border: 2rpx solid #EA3D37;
			color: #EA3D37;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 24rpx;
		}

		.kuang {
			width: 210rpx;
			height: 210rpx;
			background: linear-gradient(92.49deg, #F88E87 0%, #EA3D37 100%);
			border-right: 4rpx dashed #EA3D37;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 32rpx;
			color: #fff;

			.big {
				font-size: 72rpx;
				font-weight: bold;
			}
		}
	}

	.gray {
		color: #999999 !important;
		border: 2rpx solid #999999 !important;
	}
</style>